package com.zbkj.common.request.project;

import com.zbkj.common.exception.CommonException;
import com.zbkj.common.model.project.ProjectParamJun;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * @Auther:
 * @Date: 2024/10/7 17:54
 * @Description:
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "ProjectParamJunRequest对象", description = "项目军标调整因子保存请求对象")
public class ProjectParamJunRequest {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("关键性F1")
    private Integer paramVal1;

    @ApiModelProperty("分布式处理F2")
    private Integer paramVal2;

    @ApiModelProperty("性能F3")
    private Integer paramVal3;

    @ApiModelProperty("计算机资源限制F4")
    private Integer paramVal4;

    @ApiModelProperty("复杂处理F5")
    private Integer paramVal5;

    @ApiModelProperty("可重用性F6")
    private Integer paramVal6;

    @ApiModelProperty("多环境F7")
    private Integer paramVal7;


    /**
     * 检查参数并组装为对应pojo参数
     * @param paramJunRequest
     * @return
     */
    public static ProjectParamJun paramJunCheckAndToPojo(ProjectParamJunRequest paramJunRequest) {
        if(Objects.isNull(paramJunRequest)) {
            throw new CommonException("请填写调整因子");
        }
        junParamValCheck(paramJunRequest.getParamVal1());
        junParamValCheck(paramJunRequest.getParamVal2());
        junParamValCheck(paramJunRequest.getParamVal3());
        junParamValCheck(paramJunRequest.getParamVal4());
        junParamValCheck(paramJunRequest.getParamVal5());
        junParamValCheck(paramJunRequest.getParamVal6());
        ProjectParamJun paramJun = new ProjectParamJun();
        BeanUtils.copyProperties(paramJunRequest,paramJun);
        paramJun.setPtype(0);
        return paramJun;
    }

    public static void junParamValCheck(Integer val) {
        if(Objects.isNull(val) || !(val >=0 && val <=2)) {
            throw new CommonException("调整因子参数值错误");
        }
    }
}
